package com.fzy.silntgym.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.fzy.silntgym.R;

import static com.fzy.silntgym.R.color.white;

public class RegisterActivity extends AppCompatActivity {
    long exitTime = 0L;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        Button button = (Button)findViewById(R.id.signup);
        if (button != null) {
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    EditText username = (EditText)findViewById(R.id.username_re);
                    EditText password = (EditText)findViewById(R.id.password_re);
                    EditText nickname = (EditText)findViewById(R.id.nickname_re);
                    if(username == null || password == null){
                        Toast.makeText(getApplicationContext(),"账号和密码不能为空",Toast.LENGTH_SHORT).show();
                    }
                    else if(nickname == null){
                        Toast.makeText(getApplicationContext(),"昵称不能为空",Toast.LENGTH_SHORT).show();
                    }
                    else{
                    Toast.makeText(getApplicationContext(),"注册成功等待审核",Toast.LENGTH_SHORT).show();
                    finish();
                    }
                }
            });
        }
    }
    //TODO get user profile from mysql




    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 3000) {
                Toast.makeText(getApplicationContext(), "再按一次返回",
                        Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
            } else {
                finish();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
